import Vue from 'vue'
import VueRouter from 'vue-router'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

Vue.use(VueRouter)

const routes = [
  // dashboard
  {
    path: '/',
    redirect: '/dashboard/home/analysis'
  },
  {
    path: '/dashboard',
    name: 'dashboard',
    meta: {icon: 'dashboard', title: '仪表盘'},
    // 基础骨架
    component: () => import('@/layouts/BasicLayout'),
    children: [
      {
        path: 'home',
        name: 'home',
        redirect: 'home/analysis',
        component: { render: h => h('router-view')},
        children: [
          {
            path: 'analysis',
            name: 'analysis',
            meta: {icon: '', title: '首页'},
            // 分析组件
            component: () => import('@/views/Dashboard/Analysis')
          },
          {
            path: 'bab',
            name: 'bab',
            meta: {icon: '', title: '首页'},
            // 分析组件
            component: () => import('@/views/Dashboard/Bab')
          },  
        ] 
      },
      
      // 收银台
      {
        path: 'cashier',
        name: 'cashier',
        redirect: 'cashier/officecashier',
        component: { render: h => h('router-view')},
        children: [
          {
            path: 'officecashier',
            name: 'officecashier',
            meta: {icon: '', title: '收银台'},
            component: () => import('@/views/Dashboard/cashier/OfficeCashier'),
          }
        ]
      },
      // 订单管理
      {
        path: 'ordermanage',
        name: 'ordermanage',
        redirect: '/dashboard/ordermanage/orderlist',
        component: { render: h => h('router-view')},
        children: [
          {
            path: 'orderlist',
            name: 'orderlist',
            meta: {icon: '', title: '订单管理'},
            component: () => import('@/views/Dashboard/OrderManage/PaymentOrder'),
          },
          {
            path: 'paymentdatail',
            name: 'paymentdatail',
            meta: {icon: '', title: '订单管理'},
            component: () => import('@/views/Dashboard/OrderManage/PaymentDetail'),
          },
        ]
      },
      // 对账中心
      {
        path: 'checkcenter',
        name: 'checkcenter',
        redirect: '/dashboard/checkcenter/cashiercheck',
        component: { render: h => h('router-view')},
        children: [
          {
            path: 'cashiercheck',
            name: 'cashiercheck',
            meta: {icon: '', title: '对账中心'},
            component: () => import('@/views/Dashboard/CheckCenter/CashierCheck'),
          },
        ]
      },
      // 应用管理
      {
        path: 'appmanage',
        name: 'appmanage',
        redirect: '/dashboard/appmanage/os',
        component: { render: h => h('router-view')},
        children: [
          {
            path: 'os',
            name: 'os',
            meta: {icon: '', title: '应用管理'},
            component: () => import('@/views/Dashboard/AppManage/PaySystem'),
          },
          // {
          //   path: 'paymentdatail',
          //   name: 'paymentdatail',
          //   meta: {icon: '', title: '订单管理'},
          //   component: () => import('@/views/Dashboard/OrderManage/PaymentDetail'),
          // },
        ]
      },
      // 平台市场
      {
        path: 'appmarket',
        name: 'appmarket',
        redirect: '/dashboard/appmarket/oslist',
        component: () => import('@/views/Dashboard/AppMarket'),
        children: [
          {
            path: 'oslist',
            name: 'appmarket',
            meta: {icon: '', title: '平台市场'},
            component: () => import('@/views/Dashboard/AppMarket/OsList'),
          },
          {
            path: 'osdetail',
            name: 'osdetail',
            meta: {icon: '', title: '平台市场'},
            component: () => import('@/views/Dashboard/AppMarket/OsDetail'),
          },
        ]
      },
      // 设置
      {
        path: 'setting',
        name: 'setting',
        redirect: '/dashboard/setting/sharedmerchant',
        component: () => import('@/views/Dashboard/ProjectSetting'),
        children: [
          {
            path: 'sharedmerchant',
            name: 'sharedmerchant',
            meta: {icon: '', title: '设置'},
            component: () => import('@/views/Dashboard/ProjectSetting/SharedMerchant'),
          },
          {
            path: 'employees',
            name: 'employees',
            meta: {icon: '', title: '设置'},
            component: () => import('@/views/Dashboard/ProjectSetting/employees'),
          },
        ]
      },
    ]
  },
  // user
  {
    path: '/user',
    hideInMenu: true,
    // component: () => import('@/components/RenderRouterView.vue'),
    // component: { render: h => h('router-view')},
    component: () => import('@/layouts/UserLayout.vue'),
    children: [
      {
        path: '/user',
        redirect: '/user/login'
      },
      {
        path: 'register',
        name: 'register',
        component: () => import('@/views/User/Register')
      },
      {
        path: 'login',
        name: 'login',
        component: () => import('@/views/User/Login')
      }
    ]
  },
  // form
  {
    path: '/form',
    name: 'form',
    component: {render: h => h('router-view')},
    meta: {icon: 'from', title: '表单'},
    children: [
      {
        path: '/form/basic-form',
        name: 'basicform',
        meta: {icon: '',title: '基础库存'},
        component: () => import('@/views/Forms/BasicForm')
      },
      {
        path: '/form/step-form',
        name: 'stepform',
        meta: {title: '分布表单'},
        hideChildrenInMenu: true,
        component: () => import('@/views/Forms/StepForm'),
        children: [
          {
            path:'/form/step-form',
            redirect: '/form/step-form/info'
          },
          {
            path: '/form/step-form/info',
            name: 'info',
            component: () => import('@/views/Forms/StepForm/Step1')
          },
          {
            path: '/form/step-form/confirm',
            name: 'confirm',
            component: () => import('@/views/Forms/StepForm/Step2')
          },
          {
            path: '/form/step-form/result',
            name: 'result',
            component: () => import('@/views/Forms/StepForm/Step3')
          },
        ]
      },
    ]
  },
  {
    path: '/www',
    name: 'www',
    meta: {icon: 'cloud', title: 'wwwwww'}
  },
  {
    path: '*',
    hideInMenu: true,
    component: () => import('@/components/Nofind')
  }
]

const router = new VueRouter({
  // mode: 'history',
  routes
})

router.beforeEach((to, from, next) => {
  window.console.log('tooooooo', to.path)
  window.console.log('frommmmm', from.path)
  if(to.path !== from.path) {
    NProgress.start()
  }
  next()
})

router.afterEach(() => {
  NProgress.done()
})

export default router
